/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Database;

import Models.Profile;
import Models.Room;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author trang_000
 */
public class ManagementDAO {
    private Connection con;
    public ManagementDAO(){
        con = DBFactory.createConnection("dormitoryv2");
    }
    
    public List<Profile> getAllProfile(){
        List<Profile> results = new ArrayList<>();
        try {
            //get parent categories
            String sqlst = "SELECT * FROM profile ";
            PreparedStatement ps = con.prepareStatement(sqlst);
            ResultSet rs = ps.executeQuery();
            while (rs.next()) {
                int idProfile = rs.getInt("profileID");
                String studentCode = rs.getString("codeStudent");
                String address = rs.getString("addresse");
                String phoneNo = rs.getString("phoneNumber");
                String email = rs.getString("email");
                Date dob = rs.getDate("birthdate");
                int status = rs.getInt("status");
                int gender = rs.getInt("gender");
                String firstName = rs.getString("firstName");
                String lastName = rs.getString("lastName");
                
                Profile profile = new Profile(idProfile,studentCode, address, phoneNo, email, dob, status, gender, firstName, lastName);
               
                //add to results
                results.add(profile);
            }
        } catch (SQLException ex) {
            Logger.getLogger(ManagementDAO.class.getName()).log(Level.SEVERE, null, ex);
        }
        return results;
    }
}
